﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace Sym_i2c
{
    public class Slave
    {

        public string name, address, number;
        public string[,] memory;
        public string[] registry;
        public Slave(int num) { address = GetIntBinaryString(num); number = num.ToString(); memory = new string[256, 8]; registry = new string[8]; init(); }
        public void init()
        {
            for (int i = 0; i < 256; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    memory[i,j] = "0";    
                }
            }
            for (int i = 0; i < 8; i++)
            {
                registry[i] = "0";
            }
        }
        public string GetIntBinaryString(int n)
        {
            char[] b = new char[7];
            int pos = 6;
            int i = 0;

            while (i < 7)
            {
                if ((n & (1 << i)) != 0)
                {
                    b[pos] = '1';
                }
                else
                {
                    b[pos] = '0';
                }
                pos--;
                i++;
            }
            return new string(b);
        }
        public void assignAddresses()
        {
            address = GetIntBinaryString(Int32.Parse(number));
        }
    }
}
